package com.heantai.easystruts.tag;

import java.io.IOException;
import java.util.Locale;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

public class MessageTag extends SimpleTagSupport {
	//引擎将jsp中的key值赋给key，再调用doTag()方法
	private String key;

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	@Override
	public void doTag() throws JspException, IOException {
		PageContext pc = (PageContext)getJspContext();
		ServletContext sc = pc.getServletContext();
		HttpSession session=pc.getSession();
		Locale locale=(Locale) session.getAttribute("locale");
		System.out.println(locale.getDisplayName());
		Map<String, String> map=(Map<String, String>) sc.getAttribute(locale.getDisplayName());
		JspWriter out = pc.getOut();
		System.out.println(key);
		System.out.println(map);
		out.print(map.get(key));
	}
}
